using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsPhoneGame1.LevelItems;
using Microsoft.Xna.Framework;

namespace WindowsPhoneGame1.Collisions
{
    public class Collision : IComparable<Collision>
    {
        LevelItem a;
        LevelItem b;
        float distance;

        public Collision(LevelItem a, LevelItem b)
        {
            this.a = a;
            this.b = b;
            distance = new Vector2(a.Position.X - b.Position.X, a.Position.Y - b.Position.Y).Length();
        }

        public LevelItem A
        {
            get { return a; }
        }

        public LevelItem B
        {
            get { return b; }
        }

        public float Distance
        {
            get { return distance; }
        }

        public ContainmentType GetContainmentType()
        {
            return a.CollisionShape.contains(b.CollisionShape);
        }

        public CollisionType CollisionType
        {
            get
            {
                if (a is Car && b is TrackItem ||
                    b is Car && b is TrackItem)
                    return CollisionType.ChassisOntrack;

                if (a is Wheel && b is TrackItem ||
                    b is Wheel && a is TrackItem)
                    return CollisionType.WheelOnTrack;
                /*
                if ((a is Car || a is Wheel) && b is Coin ||
                    (b is Car || b is Wheel) && a is Coin)
                    return CollisionType.OnCoin;
                */
                return CollisionType.None;
            }
        }
            
        public int CompareTo(Collision obj)
        {
            if (this.distance > obj.Distance)
                return 1;

            if (this.Distance < obj.Distance)
                return -1;

            return 0;
        }
    }
}
